package dartstools;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.GraphicsEnvironment;
import java.io.IOException;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

/**
 *
 * @author Chris
 */
public class Theme {

    private static final String FONTS_LOC = "/resources/";
    public static final Theme[] THEMES = new Theme[]{
        new Theme(new Font("Arial", Font.PLAIN, 1), 0.9, Color.WHITE, Color.BLACK, new Color(255, 255, 255, 50)),
        new Theme("ChalkBoard.ttf", 0.9, Color.WHITE, Color.BLACK, new Color(255, 255, 255, 50)),
        new Theme("ChalkDust.ttf", Color.WHITE, Color.BLACK, new Color(255, 255, 255, 50)),
        new Theme("Chalkduster.ttf", Color.WHITE, Color.BLACK, new Color(255, 255, 255, 50)),
        new Theme("rayando.ttf", Color.WHITE, Color.BLACK, new Color(255, 255, 255, 50)),
        new Theme("GreenLights.otf", Color.GREEN, Color.BLACK, new Color(255, 255, 255, 50)),
        new Theme("BAZARONI.TTF", Color.WHITE, Color.BLACK, new Color(255, 255, 255, 50))
    };
    public static final Theme ACTIVE_THEME = THEMES[6];
    public static final Color FOREGROUND = ACTIVE_THEME.foreground,
            BACKGROUND = ACTIVE_THEME.background,
            SELECTION = ACTIVE_THEME.selection;
    public static String FONT_FAMILY;
    public static final int FONT_SMALLEST = (int) (5 * ACTIVE_THEME.fontScaler),
            FONT_SMALLER = (int) (10 * ACTIVE_THEME.fontScaler),
            FONT_SMALL = (int) (15 * ACTIVE_THEME.fontScaler),
            FONT_MEDIUM = (int) (20 * ACTIVE_THEME.fontScaler),
            FONT_LARGE = (int) (30 * ACTIVE_THEME.fontScaler),
            FONT_LARGER = (int) (40 * ACTIVE_THEME.fontScaler),
            FONT_LARGEST = (int) (50 * ACTIVE_THEME.fontScaler);
    public static final Border BORDER = new TitledBorder(new LineBorder(new Color(255, 255, 255, 75), 2, true));
    public static Font font;

    static {
        try {
            if (ACTIVE_THEME.fontfileName != null) {
                font = Font.createFont(Font.TRUETYPE_FONT, Theme.class.getResourceAsStream(FONTS_LOC + ACTIVE_THEME.fontfileName));
                GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(font);
            }
            else
                font = ACTIVE_THEME.internalFont;
            FONT_FAMILY = font.getFamily();
        }
        catch (FontFormatException | IOException ex) {
            System.err.println(ex.getMessage());
        }
    }

    /* end of static */
    private final Color foreground, background, selection;
    private final double fontScaler;
    private final String fontfileName;
    private final Font internalFont;

    public Theme(Font fontName, double fontScaler, Color foreground, Color background, Color selection) {
        this.internalFont = fontName;
        this.fontfileName = null;
        this.fontScaler = fontScaler;
        this.foreground = foreground;
        this.background = background;
        this.selection = selection;
    }

    public Theme(String fontFileNameDotTTF, double fontScaler, Color foreground, Color background, Color selection) {
        this.fontfileName = fontFileNameDotTTF;
        this.internalFont = null;
        this.fontScaler = fontScaler;
        this.foreground = foreground;
        this.background = background;
        this.selection = selection;
    }

    public Theme(String FontFileNameTTF, Color foreground, Color background, Color selection) {
        this(FontFileNameTTF, 1, foreground, background, selection);
    }

}
